<template>
  <div id="tab-control">
    <div
      id="tab-control-item"
      v-for="(item, index) in titles"
      :key="item"
      @click="itemTab(index) "
    >
      <span :class="{ atv: currentIndex === index }">{{ item }}</span>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      currentIndex: 0,
    };
  },
  props: {
    titles: {
      type: Array,
      default: [],
    },
  },
  methods: {
    itemTab(index) {
      this.currentIndex = index
      //给父组件传递当前的点击的tab
      this.$emit('tabClick', index)
    },
  },
};
</script>

<style>
#tab-control {
  display: flex;
  justify-content: space-around;
  height: 40px;
  line-height: 40px;
  font-size: 14px;
  background-color: #fff;
}
#tab-control-item span {
    padding: 5px;
}
.atv {
  color: var(--color-high-text);
  border-bottom: 3px solid var(--color-high-text);
}
</style>